package org.dizena.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class DateTimeUtil
{

    public static void main(String[] args)
    {
        Long ts = System.currentTimeMillis() - 1000 * 3600 * 24;
        System.out.println(chatLastTime(ts));
    }

    public static String chatLastTime(Long ts)
    {
        Long now = System.currentTimeMillis();
        if ((now - ts) >= 1000 * 3600 * 48)
        {
            String strDateFormat = "yyyy-MM-dd HH:mm";
            SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
            return sdf.format(new Date(ts));
        }
        else if ((now - ts) >= 1000 * 3600 * 24)
        {
            String strDateFormat = "HH:mm a";
            SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat, Locale.ENGLISH);
            return "Yesterday " + sdf.format(new Date(ts));
        }
        else
        {
            String strDateFormat = "HH:mm a";
            SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat, Locale.ENGLISH);
            return sdf.format(new Date(ts));
        }
    }

    public static String ymdHms(Long ts)
    {
        String strDateFormat = "yyyy-MM-dd HH:mm:ss";
        SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
        return sdf.format(new Date(ts));
    }

}
